package com.tangqi.other;

public class Monitor extends Thread {

	private volatile Thread listener;

	private int frequency;

	public Monitor(int frequency) {
		this.frequency = frequency * 1000;
	}

	public void run() {
		listener = Thread.currentThread();
		while (listener != null) {
			System.out.println(System.currentTimeMillis());
			try {
				Thread.sleep(frequency);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public void stopMonitor() {
		listener = null;
	}

	public static void main(String[] args) {
		Monitor m = new Monitor(60);
		m.start();
	}

}
